<?php

declare(strict_types=1);

namespace DreamCat\ObjectValid\Exception;

use DreamCat\ObjectValid\Base\ValidAnnoInterface;
use JetBrains\PhpStorm\Immutable;
use JetBrains\PhpStorm\Pure;
use ReflectionParameter;
use ReflectionProperty;
use RuntimeException;
use Throwable;

/**
 * 检查的错误
 * @author vijay
 */
#[Immutable]
class CheckErrorException extends RuntimeException
{
    /**
     * @param ReflectionProperty|ReflectionParameter $reflection 对应的反射
     * @param mixed $value 传入的值
     * @param ?ValidAnnoInterface $invalid 未检查通过的注解
     * @param string $message
     * @param int $code
     * @param Throwable|null $previous
     */
    #[Pure]
    public function __construct(
        private ReflectionProperty|ReflectionParameter $reflection,
        private mixed $value,
        private ?ValidAnnoInterface $invalid = null,
        string $message = "",
        int $code = 0,
        Throwable $previous = null
    ) {
        parent::__construct($message, $code, $previous);
    }

    /**
     * @return ReflectionParameter|ReflectionProperty
     */
    public function getReflection(): ReflectionParameter|ReflectionProperty
    {
        return $this->reflection;
    }

    /**
     * @return mixed
     */
    public function getValue(): mixed
    {
        return $this->value;
    }

    /**
     * @return ?ValidAnnoInterface
     */
    public function getInvalid(): ?ValidAnnoInterface
    {
        return $this->invalid;
    }
}

# end of file
